﻿namespace Anurgath.Shoutbox.Drivers
{
    #region Usings
    using Anurgath.Shoutbox.Models;
    using Orchard;
    using Orchard.ContentManagement.Drivers;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    #endregion

    public class ShoutboxDriver : ContentPartDriver<ShoutboxPart>
    {
        #region Private variables
        private IOrchardServices _OrchardServices;
        #endregion

        #region Constructors
        public ShoutboxDriver(IOrchardServices orchardServices)
        {
            _OrchardServices = orchardServices;
        }
        #endregion

        #region Methods
        protected override DriverResult Display(ShoutboxPart part, string displayType, dynamic shapeHelper)
        {
            dynamic ShoutboxShape = ContentShape("Parts_Shoutbox", () => shapeHelper.Parts_Shoutbox(
                Posts: part.Posts,
                ShoutboxId: part.Id,
                HowManyPostsToShow: part.HowManyPostsToShow
                ));

            return ShoutboxShape;
        }

        protected override DriverResult Editor(ShoutboxPart part, dynamic shapeHelper)
        {
            return ContentShape("Parts_Shoutbox_Edit", () => shapeHelper.EditorTemplate(
                TemplateName: "Parts/Shoutbox",
                Model: part
                ));
        }

        protected override DriverResult Editor(ShoutboxPart part, Orchard.ContentManagement.IUpdateModel updater, dynamic shapeHelper)
        {
            part.Record.CreatedAt = DateTime.Now;

            updater.TryUpdateModel(part, Prefix, null, null);
            return Editor(part, shapeHelper);
        }
        #endregion
    }
}